package com.study.suanfa.shuzu;

import java.util.Arrays;

/**
 * @description: MoNiDuiLie  数组模拟队列
 * @date: 2020/11/28 0:13
 * @author: hcm
 * @version: 1.0
 */
public class MoNiDuiLie {



    public static void main(String[] args) {

        MoNiDuiLie moNiDuiLie = new MoNiDuiLie(2);

        moNiDuiLie.printData();


    }

    /**
     * 底层数组
     */
    int[] arr;
    /**
     * 队列大小
     */
    int maxSize ;

    /**
     * 队头
     */
    int headPoint;

    /**
     * 队尾
     */
    int lastPoint;
    public MoNiDuiLie() {

    }
    public MoNiDuiLie(int maxSize) {
        this.arr = new int[maxSize];
        this.maxSize = maxSize;
        this.headPoint = -1;
        this.lastPoint = -1;
    }

    /**
     * 队列是否满
     * @return
     */
    public Boolean  fullFlag(){

        return lastPoint == maxSize-1;
    }

    /**
     * 队列是否空
     */
    public Boolean nullFlag(){
        return headPoint == lastPoint;
    }

    /**
     * 入队
     */
    public void pushQueue(int data){
        if(fullFlag()) {
            System.out.println("队列已满");
        }else{
            lastPoint++;
            arr[lastPoint] = data;
        }
    }

    /**
     * 出队
     */
    public int popQueue(){
        if(nullFlag()){
            throw  new NullPointerException("队列为空");
        }
        headPoint ++ ;
        return arr[headPoint];
    }

    /**
     * 打印元素
     */
    public void printData(){
        if(nullFlag()){
            System.out.println("队列为空");
            return;
        }
       while (!nullFlag()){
           System.out.println(popQueue()+"出队");
       }
    }


}
